<template>
    <!--最大div-->
    <div style="margin-top: -10px">
        <!--新建栏-->
        <div style="border:1px solid #BFBFBF;padding: 10px;background-color: white;margin-top: 10px;height: 40px">
            <el-row :gutter="24">
                <el-col :span="2">
                    <span style="font-size: 18px;line-height:40px;margin-left: 5px">产品采购</span>
                </el-col>
                <el-col :span="7">
                    <div class="block">
                        <el-date-picker
                                v-model="value2"
                                type="daterange"
                                align="right"
                                unlink-panels
                                range-separator="至"
                                start-placeholder="开始日期"
                                end-placeholder="结束日期"
                                :picker-options="pickerOptions">
                        </el-date-picker>
                    </div>
                </el-col>
                <el-col :span="9">
                    <el-input placeholder="请输入采购主题" v-model="input" style="width: 250px;">
                        <i slot="suffix" class="el-input__icon el-icon-search"></i>
                    </el-input>
                </el-col>
                <el-col :span="6">
                    <router-link style="line-height:40px;margin-left:200px;" :to="{path:'/caigouxinz'}">
                        <el-button size="small"  type="primary" @click="jilutankuan=true">新建采购</el-button>
                    </router-link>
                </el-col>
            </el-row>
        </div>



        <!--表格数据框-->
        <div style="margin-top: 10px;border: 1px solid #BFBFBF;background-color: white">
            <div style="width: 100%;height: 40px;background-color: white;border-bottom: 1px solid #EBEEF5">
                <div class="operate" v-show="cjy">
                    <div class="selected—title" style="border-right: 0px ">
                        场景：<span>{{value7}}</span>
                    </div>
                </div>
                <div class="operate" v-show="cje">
                    <div class="selected—title" >
                        已选中<span class="selected—count">{{count}}</span>项
                    </div>
                    <div  class="selected—title2" v-show="isOne">
                        <span @click="isAddRecord=true"><i class="el-icon-circle-plus-outline"></i>添加跟进记录</span>
                    </div>
                    <div  class="selected—title1" v-show="isOne">
                        <span><i class="el-icon-edit"></i>修改</span>
                    </div>
                    <div  class="selected—title1">
                        <span><i class="el-icon-delete"></i>删除</span>
                    </div>
                </div>
            </div>
            <el-table
                    :data="caigouList"
                    style="width: 100%"
                    max-height="450"
                    :default-sort = "{prop: 'date', order: 'descending'}"
                    @selection-change="handleSelectionChange">
                <el-table-column
                        type="selection"
                        width="50"
                        align="center">
                </el-table-column>
                <el-table-column
                        prop="purchaseDh"
                        label="采购编号"
                        align="center">
                </el-table-column>
                <el-table-column
                        prop="purchaseZhuti"
                        label="采购主题"
                        align="center">
                </el-table-column>
                <el-table-column
                        prop="purchaseCgdate"
                        label="采购时间"
                        align="center">
                    <template slot-scope="d">
                        {{d.row.purchaseCgdate | formatDate}}
                    </template>
                </el-table-column>
                <el-table-column
                        prop="purchaseCgje"
                        label="采购金额"
                        align="center">
                </el-table-column>
                <el-table-column
                        prop="purchaseJbr"
                        label="经办人"
                        align="center">
                </el-table-column>
                <el-table-column
                        prop="purchaseDhdate"
                        label="到货时间"
                        align="center">
                    <template slot-scope="d">
                        {{d.row.purchaseDhdate | formatDate}}
                    </template>
                </el-table-column>
                <el-table-column
                        prop="purchaseZt"
                        label="采购状态"
                        align="center">
                </el-table-column>
            </el-table>
        </div>
        <!--分页框-->
        <div style="margin-top: 15px;border: 1px solid #BFBFBF;padding: 10px;background-color: white">
            <div style="text-align: center">
                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="pageNum"
                        :page-sizes="[2, 4, 6, 8]"
                        :page-size="pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="pageTotal"
                >
                </el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
    import {formatTimeToStr} from '../router//format.js'
    export default {
        name: "Qcpcaigou",
        data() {
            return {
                input:'',
                value2: '',
                multipleTable: [],//存放选中值的数组
                isOne:true,//选中项为1就出现添加跟进记录和修改
                //解除搜索是否显示
                seek:false,

                //选择日期
                pickerOptions: {
                    shortcuts: [{
                        text: '最近一周',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近一个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近三个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                            picker.$emit('pick', [start, end]);
                        }
                    }]
                },
                value7: '',
                //场景一
                cjy:true,
                //场景二
                cje:false,
                //表格
                caigouList: [],
                //分页
                pageSize:4,//页大小
                pageTotal:0,//内容总条数
                pageNum: 1,//当前页
            }
        },
        methods: {
            caigou(){
                this.$axios.post("http://localhost:8088/per/caigou-list",this.qs.stringify({
                    pageNum:this.pageNum,PageSize:this.pageSize
                })).then(v=>{
                    this.pageTotal = v.data.total;
                    this.caigouList=v.data.rows;
                }).catch()
            },
            handleSizeChange(val) {
                this.pageSize = val;
                this.caigou();
            },
            //翻页数 改变信息
            handleCurrentChange(v){
                this.pageNum = v;
                this.caigou();
            },
            //复选框选中的
            handleSelectionChange(val) {
                this.multipleTable = val;//  this.multipleTable 选中的值
                if(this.multipleTable.length>0){
                    this.cjy=false;//第一行隐藏
                    this.cje=true;//批量操作栏出现
                }
                //选中项大于1不能执行添加跟进记录和修改按钮
                if(this.multipleTable.length>1){
                    this.isOne=false;
                }else if(this.multipleTable.length==0){//选中项为0时
                    this.cjy=true;//第一行出现
                    this.cje=false;//批量操作栏隐藏
                }else{
                    this.isOne=true;//添加跟进记录和修改出现
                }
                window.console.log(val);
            },
            /*选择类型商机方法*/
            changebusni(){
                if(this.value7!=''){
                    this.seek=true;
                }
            },
            /*解除选择类型商机方法*/
            cancelseek(){
                this.value7='';
                this.seek=false;
            }
        },
        computed:{
            count(){
                return this.multipleTable.length
            }
        },
        created:function() {
            this.caigou(this.pageNum,this.pageSize);
        },
        filters: {
            formatDate: function (time) {
                if (time != null && time != "") {
                    var date = new Date(time);
                    return formatTimeToStr(date, "yyyy-MM-dd hh:mm");
                } else {
                    return "";
                }
            }
        }

    }
</script>

<style scoped>

    .addview:hover{
        color: white;
    }
    a{
        text-decoration: none;
        color: #409EFF;
    }
    a:hover{
        color: white;
    }
    .busin:hover{
        color: #3E84E9;
        cursor:pointer;
    }
    .businame{
        color: #606266;
    }
    .businame:hover{
        color: #409EFF;
        cursor:pointer;
    }
    .operate{
        font-size: 12px;
        height: 40px;
        padding: 0 20px;
        color: #777;
        background: white;
    }
    .selected—title{
        margin-top: 15px;
        margin-left: -6px;
        border-right: 1px solid #e6e6e6;
        width: 86px;
        height:20px;
        float: left;
    }
    .selected—title1{
        margin-top: 15px;
        border-right: 1px solid #e6e6e6;
        width: 86px;
        height:20px;
        float: left;
        cursor: pointer;
    }

    .selected—title1 span{
        margin-left: 24px;
    }
    .selected—title1 span:hover{
        color:#409eff;
    }
    .selected—title2{
        margin-top: 15px;
        border-right: 1px solid #e6e6e6;
        width: 129px;
        height:20px;
        float: left;
        cursor: pointer;
    }

    .selected—title2 span{
        margin-left: 24px;
    }
    .selected—title2 span:hover{
        color:#409eff;
    }
</style>